package com.realtime;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class AvoidDuplicatesFromListObject {

	public static void main(String[] args)
	{
		List li = new ArrayList();

		      li.add("one");
		      li.add("two");
		      li.add("three");
		      li.add("one");//Duplicate
		      li.add("one");//Duplicate

		      System.out.println("Array List with duplicate values"+li);
		      
		     // We have facility to pass a List into Set constructor and vice verse to cast      

		        List li2 = new ArrayList(new HashSet(li)); //no order

		     // List li2 = new ArrayList(new LinkedHashSet(li)); //If you need to preserve the order use 'LinkedHashSet'

		        System.out.println("Array List with out duplicate values"+li2);
		        
		     Iterator it= li2.iterator();
		     while(it.hasNext())
		     {
		    	 System.out.println(it.next());
		     }

	}
}